package edu.whu.rose.clock.kps.algorithm.blinks2.binding;

import java.util.ArrayList;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import edu.whu.rose.clock.kps.algorithm.blinks2.index.KNEntry2;

public class KNListBinding2 extends TupleBinding {

	public Object entryToObject(TupleInput input) {
		int size = input.readInt();
		KNEntry2[] list = new KNEntry2[size];
		for (int i = 0; i < size; i++) {
			short distance = input.readShort();
			int node = input.readInt();
			int knode = input.readInt();
			int first = input.readInt();
			KNEntry2 kne = new KNEntry2(distance, node, knode, first);
			list[i] = kne;
		}
		return list;
	}
	
	public void objectToEntry(Object object, TupleOutput output) {
		ArrayList<KNEntry2> list = (ArrayList<KNEntry2>)object;
		output.writeInt(list.size());
		for (int i = 0; i < list.size(); i++) {
			KNEntry2 kne = list.get(i);
			output.writeShort(kne.getDistance());
			output.writeInt(kne.getNode());
			output.writeInt(kne.getKnode());
			output.writeInt(kne.getFirst());
		}
	}

}
